package com.clsz.controller;

import com.clsz.bean.bo.CinemaSearchBo;
import com.clsz.bean.po.Brand;
import com.clsz.bean.po.CinemaInfo;
import com.clsz.bean.po.SpecialHallInfo;
import com.clsz.bean.vo.FilmVo;
import com.clsz.service.CinemaDetailService;
import com.clsz.service.CinemaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/cinema")
public class CinemaController {
    @Autowired
    private CinemaService cinemaService;
    @Autowired
    private CinemaDetailService cinemaDetailService;

    /**
     *影院 放映厅 搜索数据
     * @return
     */
    @PostMapping
    public Object cinemaList(CinemaSearchBo cinemaSearchBo) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        cinemaService.getCinemaList();
        List<Brand> brandList = cinemaService.getBrandList(); //影院
        List<SpecialHallInfo> specialHallList = cinemaService.getSpecialHallList();//放映厅
        List<CinemaInfo> cinemaInfoList = cinemaService.searchCinema(cinemaSearchBo);
        data.put("brandList", brandList);
        data.put("specialHallList", specialHallList);
        data.put("searchDataList", cinemaInfoList);
        res.put("code", "200");
        res.put("message", "ok");
        res.put("data", data);
        res.put("searchBo", cinemaSearchBo);
        return res;
    }

    /**
     * 影院详情
     * @param cinemaId
     * @return
     */
    @GetMapping("/{cinemaId}")
    public Object getCinemaDetail(@PathVariable("cinemaId") Integer cinemaId) {
        Map<String, Object> res = new HashMap<>();
        Map<String, Object> data = new HashMap<>();
        CinemaInfo cinema = cinemaDetailService.getCinema(cinemaId);
        if (cinema == null) {
            res.put("code", "500");
            res.put("message", "数据不存在");
        } else {
            res.put("code", "200");
            res.put("message", "ok");
            List<FilmVo> filmVoList =cinemaDetailService.getFilmVo(cinemaId);
            data.put("cinema", cinema);
            data.put("filmVoList", filmVoList);
            res.put("data", data);
        }
        return res;
    }

}
